<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">

		<style type="text/css">			
 			.ui-datatable-scrollable-header-box {
				margin-left: 0px;
				margin-right: 15px !important;
			} 
/* 			iframe {
			  	width:100% !important;
			  	height:800px !important;
			} */
			select {
			    border-radius: 3px;
			}
			.box-header {
			    border-top:3px solid #3c8dbc;
			    border-top-right-radius: 3px;
			    border-top-left-radius: 3px;
			}
			#toolbarDiv {
				border-top:2px solid #ccc;
			    border-top-right-radius: 3px;
			    border-top-left-radius: 3px;
			}
			/* .ui-dialog .ui-dialog-titlebar {
			    margin: 0px 20px 0px 20px !important;
			} */
		</style>
		<script>
			//打开新建互查页面
			var addInspectOtherDialogIndex;
			function openAddInspectOtherPlanDialog() {
				var targetSrc = "/ui/equipmentAssessment/assessmentplan/dialog/addInspectOtherPlanDialog.xhtml";
				addInspectOtherDialogIndex = layer.open({
					type : 2,
					area : [ '80%', '80%' ],
					fixed : false, //不固定
					title : '互查计划-新建',
					maxmin : true,
					content : targetSrc,
					full: function(layero, index) {
						var body = layer.getChildFrame('body', index);
                        var mframe = window.top.$('iframe');
                        var height = $(mframe).height();
                        var dtHeight = height-130;
                        body.find(".ui-datatable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
					},
					restore: function(layero, index) {
						var body = layer.getChildFrame('body', index);
                        var mframe = window.top.$('iframe');
                        var height = $(mframe).height();
                        var dtHeight = height-130;
                        body.find(".ui-datatable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
					}
				});
			}
			// 打开新建自查计划页面
			var addInspectSelfDialogIndex;
			function openAddInspectSelfPlanDialog() {
				var targetSrc = "/ui/equipmentAssessment/assessmentplan/dialog/addOrEditInspectSelfPlanDialog.xhtml";
				addInspectSelfDialogIndex = layer.open({
					type : 2,
					area : [ '80%', '80%' ],
					fixed : false, //不固定
					title : '自查计划-新建',
					maxmin : true,
					content : targetSrc,
					full: function(layero, index) {
						var body = layer.getChildFrame('body', index);
                        var mframe = window.top.$('iframe');
                        var height = $(mframe).height();
						var dtHeight = height-108;
                        body.find(".ui-treetable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
					},
					restore: function(layero, index) {
						var body = layer.getChildFrame('body', index);
                        var mframe = window.top.$('iframe');
                        var height = $(mframe).height();
						var dtHeight = height-108;
                        body.find(".ui-treetable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
					}
				});
			}
			//打开计划编辑页面
			var editInspectionPlanDialogIndex;
			function openEditInspectionPlanDialog(targetSrc,title,type) {
				if(type=='InspectOther') {
					editInspectionPlanDialogIndex = layer.open({//编辑互查页
						type : 2,
						area : [ '80%', '80%' ],
						fixed : false, //不固定
						title : title,
						maxmin : true,
						content : targetSrc,
						full: function(layero, index) {
							var body = layer.getChildFrame('body', index);
	                        var mframe = window.top.$('iframe');
	                        var height = $(mframe).height();
	                        var dtHeight = height-130;
	                        body.find(".ui-datatable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
						},
						restore: function(layero, index) {
							var body = layer.getChildFrame('body', index);
	                        var mframe = window.top.$('iframe');
	                        var height = $(mframe).height();
	                        var dtHeight = height-130;
	                        body.find(".ui-datatable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
						}
					});
				}else {//编辑自查页
					editInspectionPlanDialogIndex = layer.open({
						type : 2,
						area : [ '80%', '80%' ],
						fixed : false, //不固定
						title : title,
						maxmin : true,
						content : targetSrc,
						full: function(layero, index) {
							var body = layer.getChildFrame('body', index);
	                        var mframe = window.top.$('iframe');
	                        var height = $(mframe).height();
							var dtHeight = height-108;
	                        body.find(".ui-treetable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
						},
						restore: function(layero, index) {
							var body = layer.getChildFrame('body', index);
	                        var mframe = window.top.$('iframe');
	                        var height = $(mframe).height();
							var dtHeight = height-108;
	                        body.find(".ui-treetable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
						}
					});
				}
				
			}
			//打开计划查看页面
			function openInspectionPlanDetail(planId,inspectType) {
				var targetSrc;
				if(inspectType=='InspectionSelf') {
					targetSrc = "/ui/equipmentAssessment/assessmentplan/dialog/lookupInspectSelfDialog.xhtml?id="+planId;
				}else {
					targetSrc = "/ui/equipmentAssessment/assessmentplan/dialog/lookupInspectOtherDialog.xhtml?id="+planId;
				}
				layer.open({
					type : 2,
					area : [ '80%', '80%' ],
					fixed : false, //不固定
					title : '查看',
					maxmin : true,
					content : targetSrc,
					full: function(layero, index) {
						var body = layer.getChildFrame('body', index);
                        var mframe = window.top.$('iframe');
                        var height = $(mframe).height();
						var dtHeight = height-84;
                        body.find(".ui-datatable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
					},
					restore: function(layero, index) {
						var body = layer.getChildFrame('body', index);
                        var mframe = window.top.$('iframe');
                        var height = $(mframe).height();
						var dtHeight = height-84;
                        body.find(".ui-datatable-scrollable-body").attr('style','height:'+dtHeight+'px;overflow-y:scroll');
					}
				});
			}
			//弹窗返回
			function dialogReturn(index, data) {
				var params = [];
				data = eval("(" + data + ")");
				if (index == addInspectOtherDialogIndex) {
					params.push({
						name : 'inspectionPlanId',
						value : data.inspectionPlanId
					});
					onAddInspectPlanDialogReturn(params);
				}
				if (index == addInspectSelfDialogIndex) {
					params.push({
						name : 'inspectionPlanId',
						value : data.inspectionPlanId
					});
					onAddInspectPlanDialogReturn(params);
				}
				if(index == editInspectionPlanDialogIndex) {
					params.push({
						name : 'inspectionPlanId',
						value : data.inspectionPlanId
					});
					onEditInspectPlanDialogReturn(params);
				}
			}
		</script>
	</ui:define>
	<ui:define name="content">
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<div id="headDiv" class="box box-solid with-border">
			<h:form id="headForm">
				<div class="box-header" id="queryDiv">										
					<p:outputLabel value="状态:" style="margin-left:3px;"/>
					<h:selectOneMenu id="status" value="#{assessmentPlanListController.query.status}"
						style="width:100px;height:28px;margin-left:5px">
						<f:selectItem itemLabel="全部" itemValue="" />
						<f:selectItem itemLabel="草稿"  itemValue="0"/>
						<f:selectItem itemLabel="已发布"  itemValue="1"/>
						<f:selectItem itemLabel="进行中"  itemValue="2"/>
						<f:selectItem itemLabel="已完成"  itemValue="3"/>
					</h:selectOneMenu>
					<p:outputLabel value="评价计划：" style="margin-left:15px;" />
					<p:autoComplete dropdown="true" id="planSearch"
						value="#{assessmentPlanListController.query.planName}"
						style="margin-left:5px;" size="18"
						scrollHeight="200" placeholder="输入拼音首字母查询"
						completeMethod="#{assessmentPlanListController.completePlanName}">
						<p:ajax update="form:dataTb headForm:toolbar" event="itemSelect"
							listener="#{assessmentPlanListController.queryByName()}" oncomplete="getTableScrollHeight()"/>
					</p:autoComplete>
					
					<p:outputLabel value="评价时间:" style="margin-left:15px;"/>
					<p:calendar navigator="true" autocomplete="off" style="margin-left:5px;" id="startTime"
						value="#{assessmentPlanListController.query.startTime}" pattern="yyyy-MM-dd" />
			 		<p:outputLabel value="至" style="margin-left:5px;"/>
			 		<p:calendar navigator="true" style="margin-left:5px;" id="endTime"
						value="#{assessmentPlanListController.query.endTime}" pattern="yyyy-MM-dd" />
					<p:commandButton icon="ui-icon-search" value="查询" actionListener="#{assessmentPlanListController.query()}"
						oncomplete="getTableScrollHeight()"
						update="form:dataTb" style="margin-left:15px;"/>
					<p:commandButton icon="ui-icon-refresh" value="重置"  actionListener="#{assessmentPlanListController.clearQuery()}"
						update="form:dataTb planSearch startTime endTime status responsible creator" oncomplete="getTableScrollHeight()"
						style="margin-left:5px;"/>
							
					<div class="box-tools pull-right">
						<button type="button" id="selectButton" title="高级查询" class="btn btn-default"
							onclick="onSelectDivClick();" style="margin-right: 50px;">
							<span id="selectButtonIcon" class="fa fa-caret-down">高级查询</span>
						</button>
					</div>
				</div>
				<div class="panel-collapse collapse" id="selectDiv" style="padding-left:3px">
					<h:panelGrid columns="4" style="margin-top:8px;margin-bottom:10px;margin-left:5px" cellpadding="6">
						<p:outputLabel value="负责人:" style="margin-left:5px;"/>
						<p:autoComplete placeholder="输入人员首字母可查" id="responsible" size="18"
							rendered="#{assessmentPlanListController.admin}"
							value="#{assessmentPlanListController.query.responsible}"
							completeMethod="#{assessmentPlanListController.completePersonnals}"
							scrollHeight="400" style="margin-left:10px;margin-bottom:5px;"
							 dropdown="true" />
						<p:outputLabel value="创建人:" style="margin-left:15px;"/>
						<p:autoComplete placeholder="输入人员首字母可查" id="creator" size="18"
							rendered="#{assessmentPlanListController.admin}"
							value="#{assessmentPlanListController.query.creator}"
							completeMethod="#{assessmentPlanListController.completePersonnals}"
							scrollHeight="400" style="margin-left:10px;margin-bottom:5px;"
							 dropdown="true" />
					</h:panelGrid>
				</div>
				<div id="toolbarDiv">
					<p:toolbar id="toolbar">
						<f:facet name="left">
							<p:commandButton value="新建自查计划" icon="fa fa-plus"
								rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjjh_xjzcjh')}"
								onclick="openAddInspectSelfPlanDialog()" />
							<p:commandButton id="addInspectOtherBtn" value="新建互查计划"
								rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjjh_xjhcjh')}"
								icon="fa fa-plus" onclick="openAddInspectOtherPlanDialog()" />
							<p:remoteCommand name="onAddInspectPlanDialogReturn"
								update="form:dataTb form:msgs"
								actionListener="#{assessmentPlanListController.onAddInspectPlanDialogReturn}"
								oncomplete="getTableScrollHeight()"/>

							<p:commandButton id="editBtn" value="编辑" icon="fa fa-pencil"
								rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjjh_bj')}"
								disabled="#{assessmentPlanListController.showEdit()}"
								actionListener="#{assessmentPlanListController.openEditInspectionPlanDialog()}" />
							<p:remoteCommand name="onEditInspectPlanDialogReturn"
								update="form:dataTb form:msgs"
								actionListener="#{assessmentPlanListController.onEditInspectPlanDialogReturn}"
								oncomplete="getTableScrollHeight()" />
								
							<p:commandButton id="detailBtn" value="查看" icon="fa fa-list"
								rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjjh_ck')}"
								disabled="#{assessmentPlanListController.disabledDetailBtn()}"
								onclick="openInspectionPlanDetail('#{assessmentPlanListController.getSelectedInspectionPlan().id}','#{assessmentPlanListController.getSelectedInspectionPlan().inspectionType.value}')">
							</p:commandButton>
							
							<p:commandButton id="delBtn" value="删除" icon="fa fa-trash-o"
								disabled="#{assessmentPlanListController.selectedInspectionPlans.size()==0}"
								rendered="#{s:hasPermission(session,'dwfxpg_sbyhgl_pjjh_sc')}"
								actionListener="#{assessmentPlanListController.delete()}"
								update="form:msgs form:dataTb toolbar"
								oncomplete="getTableScrollHeight()">
								<p:confirm header="提示" message="确定删除该记录吗?" icon="ui-icon-alert" />
							</p:commandButton>
						</f:facet>
					</p:toolbar>
				</div>
			</h:form>
		</div>
		<div id="infoDiv" class="box box-solid with-border">
			<h:form id="form">
				<p:growl id="msgs" showDetail="true"/>
				<p:dataTable id="dataTb" var="plan" value="#{assessmentPlanListController.plans}"
					rowKey="#{plan.id}" style="margin-bottom:0"
					emptyMessage="无记录" rows="20" paginator="true" rowIndexVar="ite"
					paginatorTemplate="{Customization} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" 
					widgetVar="dataTb" scrollable="true" selection="#{assessmentPlanListController.selectedInspectionPlans}"
					rowsPerPageTemplate="20,50,100" paginatorPosition="bottom">
					<p:ajax event="rowSelect" update="headForm:toolbar" />
					<p:ajax event="rowUnselect" update="headForm:toolbar" />
					<p:ajax event="rowSelectCheckbox" update="headForm:toolbar" />
					<p:ajax event="rowUnselectCheckbox" update="headForm:toolbar" />
					<f:facet name="{Customization}">
						<p:outputLabel value="总计：#{assessmentPlanListController.count} 条记录" style="margin-right:20px;"></p:outputLabel>
					</f:facet>
					<p:column selectionMode="multiple" style="width:20px;text-align:center"/>
					<p:column headerText="序号" style="width:36px;text-align:center">
						<h:outputText value="#{ite+1}" />
					</p:column>
					<p:column headerText="评价计划" style="width:20%">
						<h:outputText value="#{plan.name}" style="text-align:left" />
					</p:column>
	
					<p:column headerText="评价时间" style="width:15%">
						<h:outputText value="#{assessmentPlanListController.getTimeStr(plan.startTime,plan.endTime)}" style="text-align:left"></h:outputText>
					</p:column>
					<p:column headerText="实际评价时间" style="width:15%">
						<h:outputText value="#{assessmentPlanListController.getTimeStr(plan.actualStartTime,plan.actualEndTime)}" style="text-align:left"></h:outputText>
					</p:column>
					<p:column headerText="负责人" >
						<h:outputText value="#{plan.responsible}" style="text-align:left" />
					</p:column>
					<p:column headerText="创建人" >
						<h:outputText value="#{plan.creator}" style="text-align:left" />
					</p:column>
					<p:column headerText="类型" >
						<h:outputText value="#{plan.inspectionType.name}" style="text-align:left" />
					</p:column>
					<p:column headerText="状态" >
						<h:outputText style="color:#{assessmentPlanListController.statusColor};" value="#{assessmentPlanListController.getStatusStr(plan.id,plan.status)}" />
						<h:outputText rendered="#{plan.status==4}" style="color:red" value="【存储中...】"></h:outputText>
					</p:column>
					<p:column headerText="操作" style="text-align:center">
						<!-- <p:commandLink rendered="#{plan.status==1}" value="撤销" title="撤销发布"
							actionListener="#{assessmentPlanListController.returnToDraft(plan.id)}" update="form:dataTb form:msgs"
							oncomplete="getTableScrollHeight()">
							<p:confirm header="提示" message="确定撤销为草稿吗？" icon="ui-icon-alert" />
						</p:commandLink> -->
						<!-- <p:commandLink actionListener="#{assessmentPlanListController.publish(plan.id)}"
							rendered="#{plan.status==0}" value="发布" title="发布计划" update="form:dataTb form:msgs"
							oncomplete="getTableScrollHeight()">
							<p:confirm header="提示" message="确定发布该计划吗?" icon="ui-icon-alert" />
						</p:commandLink> -->
						<!-- <p:link style="border:0.5px solid #d2d6de;margin-left:5px;margin-right:5px" rendered="#{plan.status==0 or plan.status==1}" /> -->
						<p:commandLink actionListener="#{assessmentPlanListController.executeNow(plan.id)}"
							rendered="#{plan.status==0 or plan.status==1}" value="执行" title="立即执行" update="form:dataTb form:msgs"
							oncomplete="getTableScrollHeight()">
							<p:confirm header="提示" message="确定立即执行吗?" icon="ui-icon-alert" />
						</p:commandLink>
						<p:commandLink actionListener="#{assessmentPlanListController.submit(plan.id)}"
							rendered="#{plan.status==2}" value="提交" title="提交计划" update="form:dataTb form:msgs"
							oncomplete="getTableScrollHeight()">
							<p:confirm header="提示" message="#{assessmentPlanListController.getSubmitMessage(plan.id)}" icon="ui-icon-alert" />
						</p:commandLink>
						<!-- 数据存储中 -->
						<p:commandLink actionListener="#{assessmentPlanListController.refresh(plan.id)}"
							rendered="#{plan.status==4}" class="fa fa-refresh" value="刷新" title="刷新"
							oncomplete="getTableScrollHeight()">
						</p:commandLink>
					</p:column>
				</p:dataTable>
			</h:form>
		</div>
	</ui:define>
	<ui:define name="contentend">
		<script src="/resources/js/tables/singleScrollTable.js" />
	</ui:define>
</ui:composition>
